home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
CrashBurn.sit
/
Crash & Burn
/
source code
/
FireBugPPCTest.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-06-27
|
5KB
|
253 lines
#include "patches.h"
#include <traps.h>
#include <lowmem.h>
#include <iostream>
#include <qdoffscreen.h>
#include "RectUtilities.h"
#include "flames.h"
// 16777216
static CGrafPort gMyPort;
static FlameDataRecPtr gFlames = NULL;
static FlameDataRecPtr gFlames2 = NULL;
static void LockHandle(Handle h)
{
if(h){
HLock(h);
}
}
static void UnlockHandle(Handle h)
{
if(h){
HUnlock(h);
}
}
static void UnlockPixMap(PixMapHandle p)
{
if(p){
UnlockHandle((Handle)p);
UnlockHandle((Handle)p[0]->pmTable);
}
}
static void LockPixMap(PixMapHandle p)
{
if(p){
LockHandle((Handle)p);
LockHandle((Handle)p[0]->pmTable);
}
}
static void LockPixPat(PixPatHandle p)
{
if(p){
LockHandle((Handle)p);
LockPixMap(p[0]->patMap);
LockHandle((Handle)p[0]->patData);
LockHandle((Handle)p[0]->patXData);
LockHandle((Handle)p[0]->patXMap);
}
}
enum {
uppProcPtr = kPascalStackBased,
uppEntry = kPascalStackBased |
STACK_ROUTINE_PARAMETER(1,SIZE_CODE(sizeof(ProcPtr)))
};
static long gA5World;
static long g2Count;
static Boolean KeyIsDown(
short theKeyCode)
{
KeyMap theKeys;
GetKeys( theKeys); /* Get state of each key */
/* Ordering of bits in a KeyMap is truly bizarre. A KeyMap is a */
/* 16-byte (128 bits) array where each bit specifies the start */
/* of a key (0 = up, 1 = down). We isolate the bit for the */
/* specified key code by first determining the byte position in */
/* the KeyMap and then the bit position within that byte. */
/* Key codes 0-7 are in the first byte (offset 0 from the */
/* start), codes 8-15 are in the second, etc. The BitTst() trap */
/* counts bits starting from the high-order bit of the byte. */
/* For example, for key code 58 (the option key), we look at */
/* the 8th byte (7 offset from the first byte) and the 5th bit */
/* within that byte. */
return( BitTst( ((char*) &theKeys) + theKeyCode / 8,
(long) 7 - (theKeyCode % 8) ) );
}
static pascal void _IdleProc()
{
long oldA5 = SetA5(gA5World);
if(KeyIsDown(0x3B)){
StartFlames(gFlames2);
}
g2Count++;
if( (g2Count % 100) == 0){
StepFlames(gFlames);
StepFlames(gFlames2);
}
SetA5(oldA5);
}
static void DoMacsBug()
{
gA5World = SetCurrentA5();
Handle h = Get1Resource('Code',0);
if(h != NULL){
HLock(h);
UniversalProcPtr callBack = NewRoutineDescriptor((ProcPtr)_IdleProc, uppProcPtr, GetCurrentISA());
CallUniversalProc((UniversalProcPtr)*h,uppEntry,callBack);
Debugger();
PaintBehind(NULL,GetGrayRgn());
PaintOne((WindowRef)FrontWindow(),FrontWindow()->visRgn);
DrawMenuBar();
}
}
void main()
{
cout << "Init" << endl;
GDHandle mainDevice = GetMainDevice();
LockHandle((Handle)mainDevice);
LockPixMap(mainDevice[0]->gdPMap);
LockHandle((Handle)mainDevice[0]->gdITable);
LockHandle((Handle)mainDevice[0]->gdSearchProc);
LockHandle((Handle)mainDevice[0]->gdCompProc);
OpenCPort(&gMyPort);
SetPort((GrafPtr)&gMyPort);
BackColor(blackColor);
EraseRect(&gMyPort.portRect);
BackColor(whiteColor);
Rect macsBug;
Rect screenRect;
SetRect(&macsBug,0,0,640,480);
SetRect(&screenRect,0,0,0x340,624);
Point center;
center.h = screenRect.right/2;
center.v = screenRect.bottom/2;
RectUtil::CenterRectOnPoint(&macsBug,center);
RgnHandle screenRgn = NewRgn();
RgnHandle mbRgn = NewRgn();
RectRgn(screenRgn,&screenRect);
RectRgn(mbRgn,&macsBug);
DiffRgn(screenRgn,mbRgn,screenRgn);
SetClip(screenRgn);
LockPixMap(gMyPort.portPixMap);
LockHandle((Handle)gMyPort.grafVars);
LockHandle((Handle)gMyPort.visRgn);
LockHandle((Handle)gMyPort.clipRgn);
LockPixPat(gMyPort.bkPixPat);
LockPixPat(gMyPort.pnPixPat);
LockPixPat(gMyPort.fillPixPat);
double fFadeRate = 0.02;
double fDensity = 0.5;
short fMinWidth = 2;
short fMaxWidth = 4;
FlameDataRecPtr f;
Rect myRect;
Rect topRect;
topRect = macsBug;
topRect.bottom = topRect.top;
topRect.top -= 75;
myRect = gMyPort.portRect;
myRect.top = myRect.bottom - 100;
// myRect.top = myRect.bottom - 50;
// myRect.right = myRect.left + 150;
// myRect.top = myRect.bottom - 100;
// myRect.left += 200;
// myRect.right -= 200;
myRect = gMyPort.portRect;
myRect.top = myRect.bottom - 100;
f = MakeNewFlames ((GrafPtr)&gMyPort, &myRect,
fMinWidth,fMaxWidth,
fDensity, fFadeRate,
30,GetCTable(1280));
gFlames2 = MakeNewFlames ((GrafPtr)&gMyPort, &topRect,
fMinWidth,fMaxWidth,
fDensity, .04,
30,GetCTable(1280));
myRect = gMyPort.portRect;
myRect.top = myRect.bottom - 100;
myRect.left = myRect.right - 150;
LockFlames(f);
StartFlames (f);
LockFlames(gFlames2);
// StartFlames(gFlames2);
g2Count = 0;
gFlames = f;
DoMacsBug();
FreeFlames(&f);
FreeFlames(&gFlames2);
CloseCPort(&gMyPort);
UnlockHandle((Handle)mainDevice[0]->gdCompProc);
UnlockHandle((Handle)mainDevice[0]->gdSearchProc);
UnlockHandle((Handle)mainDevice[0]->gdITable);
UnlockPixMap(mainDevice[0]->gdPMap);
UnlockHandle((Handle)mainDevice);
}